package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.HomeFragment1.RecommendBean;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by d on 2016/10/14.
 */
public class Home3Adapter extends BaseAdapter {
    private Context context;
    private List<RecommendBean> beanList;//img_zhanwei
    public ImageOptions options = new ImageOptions.Builder()
            //设置加载过程中的图片
            .setLoadingDrawableId(R.mipmap.img_zhanwei)
            //设置加载失败后的图片
            .setFailureDrawableId(R.mipmap.img_zhanwei)
            //设置使用缓存
            .setUseMemCache(true)
            //设置显示圆形图片
            .setCircular(true)
            //设置支持gif
            .setIgnoreGif(false)
            .build();
    public Home3Adapter(Context context, List<RecommendBean> beanList) {
        this.context = context;
        this.beanList = beanList;
    }

    @Override
    public int getCount() {
        return beanList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.homefrag1_item,null);
            holder.mImg = (ImageView) convertView.findViewById(R.id.item_home_recycle1_image);
            holder.img = (ImageView) convertView.findViewById(R.id.img);
            holder.name = (TextView) convertView.findViewById(R.id.item_home_recycle1_name);
            holder.price = (TextView) convertView.findViewById(R.id.item_home_recycle1_price);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

//        int width = screenWidth  / 2;
//
//        ViewGroup.LayoutParams params = holder.mImg.getLayoutParams();
//
//        params.width = width;
//        params.height = width;

//        holder.mImg.setLayoutParams(params);
//        ImageLoader.getInstance().displayImage(homeList.get(position).getImg(),holder.mImg);
        //holder.mImg.setImageResource(Integer.parseInt(beanList.get(position).getImg()));
        x.image().bind(holder.mImg,beanList.get(position).getGoodImg(),options);
        holder.name.setText(beanList.get(position).getGoodName());
        holder.price.setText("¥"+beanList.get(position).getGoodPrice());
        if ("1".equals(beanList.get(position).getIs_presale())){
            if (holder.img.getVisibility() == View.GONE){
                holder.img.setVisibility(View.VISIBLE);
            }
        }else {
            if (holder.img.getVisibility() == View.VISIBLE){
                holder.img.setVisibility(View.GONE);
            }
        }
        return convertView;
    }

    private class ViewHolder {
        View layout, line;
        ImageView mImg;
        TextView name;
        TextView price;
        ImageView img;
    }
}
